/**
 * @author 史鑫鑫
 * @description 权限相关接口合集
 * @date 2021-03-06
 * @modefied 史鑫鑫
 */
import request from '@/utils/request'

/**
 * 普通的用户名/密码登录接口
 * @param {String} username 登录名/邮箱/手机号
 * @param {String} credential 用户密码
 */
export function signIn (username, credential) {
  return request({
    url: '/u/api/v2/auth/sign_in',
    method: 'post',
    data: {
      username,
      credential
    }
  })
}
/**
 * 用户短信登录/注册接口
 * @param {String} username 手机号
 * @param {String} credential 信息验证码
 */
export function smsSignIn (username, credential) {
  return request({
    url: '/u/api/v2/auth/sms/sign_in',
    method: 'post',
    data: {
      username,
      credential
    }
  })
}

/**
 * 用户邮箱登录/注册接口
 * @param {String} username 邮箱
 * @param {String} credential 信息验证码
 */
export function mailSignIn (username, credential) {
  return request({
    url: '/u/api/v2/auth/mail/sign_in',
    method: 'post',
    data: {
      username,
      credential
    }
  })
}

/**
 * 用户登出当前设备的接口
 */
export function signOut () {
  return request({
    url: '/u/api/v2/auth/sign_out',
    method: 'post'
  })
}

/**
 * 发送邮箱验证码
 * @param {String} account 账号
 */
export function mailCodeVerify (account) {
  return request({
    url: `/u/api/v2/auth/mail/code/verify/${account}`,
    method: 'post'
  })
}
/**
 * 重置用户密码
 * @param {String} newPassword 新密码
 * @param {String} phone 电话
 * @param {String} verifyCode 验证码
 */
export function resetPassword (newPassword, phone, verifyCode) {
  return request({
    url: '/u/api/v2/auth/reset_password',
    method: 'post',
    data: {
      target: newPassword,
      phone,
      verifyCode
    }
  })
}
/**
 * 重置用户密码
 * @param {String} newPassword 新密码
 * @param {String} email 邮箱
 * @param {String} verifyCode 验证码
 */
export function emailResetPassword (newPassword, email, verifyCode) {
  return request({
    url: '/u/api/v2/auth/email/reset_password',
    method: 'post',
    data: {
      target: newPassword,
      email,
      verifyCode
    }
  })
}
